<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 显示转换
    /*
    let str = "123";
    let uname = "caiWan";
    console.log(typeof (str));
    console.log(typeof (Number(str)));
    console.log(Number(uname)); // NaN
    console.log(typeof (Number(uname)));
    */

    // let num = prompt("请输入年薪：");
    // console.log(num);
    // console.log(Number(num));

    // 第一种方法 Numer()
    // let num = Number(prompt("请输入年薪："));
    // // 第二种方法 +(...)
    // let num = +prompt("请输入年薪：");
    // console.log(num);
    // console.log(typeof (num));

    // parseInt() 保留整数
    console.log(parseInt("12cc"));
    console.log(parseInt("12.34cc"));
    console.log(parseInt("12.56cc"));
    console.log(parseInt("asd12.56cc"));
    // parseFloat() 可以保留小数
    console.log(parseFloat("3.1415926菜丸"));
    console.log(parseFloat("3.1415926"));
    console.log(parseFloat("3.1415926"));
    console.log(parseFloat("asd3.1415926"));

    // testDemo
    let num1 = parseFloat(prompt("请输入第一个数："));
    let num2 = parseFloat(prompt("请输入第二个数："));
    let sum = num1 + num2;
    alert("两个数相加的和是：" + sum);
  </script>
</body>

</html>